/**
 * role-edit.js
 */

define('role-edit',['jquery','base','liger.messageBox','liger.dialog','liger.all'],function(require, exports, module){
	var Base = require("base");
	var $ = require("jquery");
	require("liger.all")($);
	var ctx = Base.common.utils.getContextPath();
	
	var dialog = frameElement.dialog;

	
	var typeEnum = {0:'超级管理员',1:'普通管理员',2:'高级用户',3:'普通用户',4:'过期用户'};//TODO 来自远程服务器
	var $form = $("#form").ligerForm({
		                 inputWidth: 170, labelWidth: 90, space: 40,
		                  fields: [
		                  { name: "id", type: "hidden" },
		                  { display: "角色名称", name: "name", newline: true, type: "text" , group: "角色信息", groupicon: 'groupicon'}, 
		                  { display: "类型", name: "type", newline: false, type: "select" ,options:{data:[{text:'超级管理员',id:'0'},
		                    {text:'普通管理员',id:'1'},{text:'高级用户',id:'2'},{text:'普通用户',id:'3'},{text:'过期用户',id:'4'}]} }
		                  ],buttons:[{
		              	  	text:'保存',
		            		click : function() {
		            	        var data = $form.getData();
		            	        data = $.extend({ id :null, name:null,type:2},data);
		            	        $.ajax({
		            	    		url: ctx+ '/role/save.do',
		            	    		type : 'POST',
		            	    		dataType : 'json',
		            	    		data : data,
		            	    		success : function(backData) {
		            	    			if(backData){
		            	    				$.ligerDialog.success("保存成功");
		            	    				$("#dataGrid").ligerGetGridManager().reload();
		            	    			}
		            	    		}
		            	    	});
		            		}
		                },{
		            	  	text:'取消',
		            		click : function() {
		            			dialog.close();
		            		}
		                }]
						}); 
	loadModifyData();
	
	function loadModifyData(){
		if(id){
			 $.ajax({
		    		url: ctx+ '/role/load.do',
		    		type : 'POST',
		    		dataType : 'json',
		    		data : {id:id},
		    		success : function(backData) {
		    			if(backData){
		    				$form.setData(backData);
		    			}
		    		}
		        });
			
			
		}
	}
	
});